package com.codemasters.puntodeventacodemasters;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class PrincipalActivity extends Activity {

	
	Button registrar;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_principal);
		
		
		registrar = (Button)findViewById(R.id.btnRegistrar);
		
		
		registrar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
			
				
			   Intent intentScanner = new Intent("com.google.zxing.client.android.SCAN"); //Lanzado el lector qr
			   intentScanner.putExtra("SCAN_MODE", "QR_CODE_MODE");
		       startActivityForResult(intentScanner, 0);
				
			}
		});
			
	}

	
	
	
	  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       if (requestCode == 0) {
    	   
    	      if (resultCode == RESULT_OK) {
    	    	  
    	        String contents = intent.getStringExtra("SCAN_RESULT"); //Asignando el dato encriptado en el qr
    	        String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
    	         
    	     

    	        
    	        Intent i = new Intent(getApplicationContext(), ResultadoDatosActivity.class); //Lanzando la segunda activity
    	        i.putExtra("PRODUCTO", contents);
    	     
    	        startActivity(i);    
    	         
    	      } else if (resultCode == RESULT_CANCELED) {
    	         
    	      }
    	   }
    	}
    

	  
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.principal, menu);
		return true;
	}

}
